# 阶段1：构建应用
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app

# 复制项目文件
COPY solution/*.sln ./solution/
COPY solution/Single.WebApp/*.csproj ./solution/Single.WebApp/
COPY solution/Single.Xunjinet/*.csproj ./solution/Single.Xunjinet/
COPY solution/Single.Sugar/*.csproj ./solution/Single.Sugar/
COPY solution/Single.Core/*.csproj ./solution/Single.Core/
COPY solution/Single.Utils/*.csproj ./solution/Single.Utils/
COPY solution/Single.Logger/*.csproj ./solution/Single.Logger/
COPY solution/Single.Json/*.csproj ./solution/Single.Json/
COPY solution/Single.Encrypt/*.csproj ./solution/Single.Encrypt/
COPY solution/Single.AppCore/*.csproj ./solution/Single.AppCore/
COPY solution/Single.Autofac/*.csproj ./solution/Single.Autofac/
COPY solution/Single.Lock/*.csproj ./solution/Single.Lock/
COPY solution/Single.YitId/*.csproj ./solution/Single.YitId/

# 还原依赖
RUN dotnet restore solution/Single.WebApp/Single.WebApp.csproj

# 复制所有源代码文件
COPY . .

# 构建应用
WORKDIR /app/solution/Single.WebApp

RUN dotnet publish -c Release -o /app/publish

# 阶段2：运行应用
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
WORKDIR /app

# 复制发布的应用程序文件
COPY --from=build /app/publish .

# 确保复制Areas目录（运行所需）
COPY --from=build /app/solution/Single.WebApp/Areas ./Areas

# 直接启动应用程序
ENTRYPOINT ["dotnet", "Single.WebApp.dll"]